export default {
  length(array) {
    return array.length;
  },

  isEquals(a, b) {
    return JSON.stringify(a) === JSON.stringify(b);
  },

  contains(array, element) {
    return array.includes(element);
  },

  isEmpty(array) {
    return array.length === 0;
  },

  indexOf(array, element) {
    for (var index in array) {
      if (array[index] == element) {
        let pInt = parseInt(index);
        return isNaN(pInt) ? index : pInt;
      }
    }
    return -1;
  },

  indexesOf(array, element) {
    var indexes = [];
    for (var index in array) {
      if (array[index] == element) {
        let pInt = parseInt(index);
        indexes.push(isNaN(pInt) ? index : pInt);
      }
    }
    return indexes;
  },

  indexOfByObjectKey(array, searchKey, searchValue) {
    for (var index in array) {
      if (array[index][searchKey] == searchValue) {
        let pInt = parseInt(index);
        return isNaN(pInt) ? index : pInt;
      }
    }
    return -1;
  },

  indexesOfByObjectKey(array, searchKey, searchValue) {
    var indexes = [];
    for (var index in array) {
      if (array[index][searchKey] == searchValue) {
        let pInt = parseInt(index);
        indexes.push(isNaN(pInt) ? index : pInt);
      }
    }
    return indexes;
  },

  getSubArray(array, startIndex, endIndex) {
    if (endIndex === undefined) {
      endIndex = array.length - startIndex;
    }
    return array.slice(startIndex, startIndex + endIndex - 1);
  },

  add(array, element) {
    array.push(element);
  },

  addArray(array1, array2) {
    array1.push(...array2);
  },

  insert(array, element, index) {
    array.splice(index, 0, element);
  },

  removeElement(array, elementToRemove) {
    for (let i = array.length - 1; i >= 0; i--) {
      if (array[i] === elementToRemove) {
        array.splice(i, 1);
      }
    }
  },

  remove(array, start, length) {
    if (length === undefined) {
      length = array.length - start;
    }
    array.splice(start, length);
  },

  reverse(array) {
    array.reverse();
  },

  clone(array) {
    return JSON.parse(JSON.stringify(array));
  },

  toString(array) {
    return array.join(', ');
  },

  stackPush(array, value) {
    return array.push(value);
  },
  stackPop(array) {
    return array.pop();
  },
  queuePush(array, value) {
    return array.unshift(value);
  },
  queuePop(array) {
    return array.pop();
  },
};